# -*- coding: utf-8 -*-

import os
import sys
import StringIO
import subprocess
from subprocess import Popen

import mmap

dotstr = """ 
 digraph G {
	rankdir=TB;
	nodesep =1;
	node [shape=record];
	a [ label ="{  Graphs can\lbe fun\l|  mid|  right}"];
	b [ label ="{  |   b |   }" ];
	c [ label ="{    | c |    }" ];
	x [ label ="{    | x |   }" ];
	y [ label ="{   | y |    }" ];
//	z [ id="z", label ="{  a | z | p2   }" ];
	a -> b ;
	a  -> d;
	a  -> y ;
	c  -> d;
	b  -> x ;
	c  -> y ;
//	b  -> z;
}
"""


f = open("er.dot","w")
f.write(dotstr)
f.close()

cmd = "dot.exe -Tsvg records.dot"
mode = "b"
bufsize = -1
(child_stdin, child_stdout) = os.popen2(cmd, mode, bufsize)
#print child_stdin
for line in child_stdout:
  print line,
